# 获取json数据
from UI自动化.pytest框架.项目名称.config import BaseDir
import json
from python接口测试.FIC_项目代号.tools_第三方工具包.dbutil import DBUtil
from xml.dom import minidom
from UI自动化.pytest框架.项目名称.config import BaseDir

# 读取json 文件生成parameterized 可用的格式 [(12,3,4),(1,2,3,4)]
def bulid_data_json():
    json_file = BaseDir+ "/data测试数据/laohuanglidata.json"
    test_data = []
    with open(json_file, encoding="utf-8") as f:
        json_data = json.load(f)
        for case_data in json_data:
            key = case_data.get("key")
            date = case_data.get("date")
            reason = case_data.get("reason")
            error_code = case_data.get("error_code")
            test_data.append((key, date, reason, error_code))
            print("test_data = {}".format(test_data))
    return test_data

# 读取数据库 数据参数化
def bulid_data_db():
    sql = "select * from laohuangli"
    db_data = DBUtil.exe_sql(sql)
    # print(db_data)
    test_data = []
    for case_data in db_data:
        key = case_data[0]
        date = case_data[1]
        reason =case_data[2]
        error_code = case_data[3]
        test_data.append((key, date, reason, error_code))
        # print("test_data = {}".format(test_data))
    return test_data



# 读取XML配置文件
def read_xml(filename,onenode,twonode):
    root = minidom.parse(filename)
    fristnode = root.getElementsByTagName(onenode)[0]
    secondnode = fristnode.getElementsByTagName(twonode)[0].firstChild.data

    return secondnode


if __name__ == '__main__':
    # bulid_data_db()

    # fileName = BaseDir+"/data测试数据/data_laohuangli.xml"
    # print(read_xml(fileName,"laohaungli","headers"))
    bulid_data_json()